<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.ResultSet" %>
<%--
  Created by IntelliJ IDEA.
  User: 电脑
  Date: 2024/10/27
  Time: 22:00
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>增</title>

</head>
<body>
<%
    String username = "root";
    String pwd = "990106";
    String url="jdbc:mysql://localhost:3306/text?serverTimezone=Asia/Shanghai";
    Class.forName("com.mysql.cj.jdbc.Driver");
    Connection conn = DriverManager.getConnection(url,username,pwd);
    Statement statement = conn.createStatement();
    int number=006;
    String name = "滚滚滚";
    String birthday = "2000-10-10";
    String stuclass = "1班";
    String sql = "insert into student(number,name,birthday,stuclass)values "+"('"+number+"','"+name+"','"+birthday+"','"+stuclass+"')";
    int result = statement.executeUpdate(sql);
    if(result>0)
        out.print("<script type='text/javascript'>alert('添加成功');</script>");
    else
        out.print("<script type='text/javascript'>alert('添加失败');</script>");
    sql = "select * from student";

    ResultSet rs = statement.executeQuery(sql);
%>
<table border="1">
    <tr colsspan="4" style="font-size: x-large;alignment: center">学生信息表</tr>
    <tr style="text-align: center">
        <td>学号</td>
        <td>姓名</td>
        <td>出生日期</td>
        <td>班级</td>
    </tr>
    <%while (rs.next()){%>
    <tr style="text-align: center">
        <td><%=rs.getString(1)%></td>
        <td><%=rs.getString(2)%></td>
        <td><%=rs.getString("birthday")%></td>
        <td><%=rs.getString("stuclass")%></td>
    </tr>
    <%}%>
    <%rs.close();
        statement.close();
        conn.close();
    %>
</table>
</body>
</html>
